package controllers

import (
	"gdshop-font-api-go/app/request/HomeReq"
	"gdshop-font-api-go/app/request/OrderReq"
	"gdshop-font-api-go/app/service/HomeService"
	"gdshop-font-api-go/app/service/OrderService"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools/token"
	"github.com/gogf/gf/net/ghttp"
)

type HomeController struct {
	*BaseController
}

func (c *HomeController) Index(r *ghttp.Request) *response.JsonResponse {
	//r.SetCtxVar("fanhui", fanhui) // 上下文
	var parames *HomeReq.Index
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Index(r.GetCtx(), parames)
}

func (c *HomeController) Preview(r *ghttp.Request) *response.JsonResponse {
	//r.SetCtxVar("fanhui", fanhui) // 上下文
	var parames *HomeReq.Preview
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Preview(r.GetCtx(), parames)
}

// 登陆
func (c *HomeController) Login(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Login
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Login(r.GetCtx(), parames)
}

// @Summary 用户注册
// @tags 公共
// @Produce json
// @Param  entity body HomeReq.Register true "注册请求"
// @Router /register [POST]
// @Success 200 {object} response.JsonResponse
func (c *HomeController) Register(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Register
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Register(r.GetCtx(), parames)
}

// 找回密码
func (c *HomeController) Forget(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Forget
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Forget(r.GetCtx(), parames)
}

// 发送验证码
func (c *HomeController) SendVCode(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.SendVCode
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.SendVCode(r.GetCtx(), parames)
}

// 快速登录、第三方登录
func (c *HomeController) QuickLogin(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Login
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.Login(r.GetCtx(), parames)
}

func (c *HomeController) Layout(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Layout
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	parames.TokenString = token.GetToken(r)
	parames.MemberId = token.GetLoginMemberId(r)
	return HomeService.Layout(r.GetCtx(), parames)
}

func (c *HomeController) Area(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Area
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}

	return HomeService.Area(r.GetCtx(), parames)
}

func (c *HomeController) Pcas(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Pcas
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}

	return HomeService.Pcas(r.GetCtx(), parames)
}

func (c *HomeController) Slides(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.Slides
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}

	return HomeService.Slides(r.GetCtx(), parames)
}
func (c *HomeController) SubmitQueue(r *ghttp.Request) *response.JsonResponse {
	var parames *OrderReq.SubmitQueue
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return OrderService.SubmitQueue(r.GetCtx(), parames)
}

func (c *HomeController) WechatInfo(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.WechatInfo
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.WechatInfo(r.GetCtx(), parames)
}

func (c *HomeController) WechatShare(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.WechatShare
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.WechatShare(r.GetCtx(), parames)
}

func (c *HomeController) WechatLogin(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.WechatLogin
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.WechatLogin(r.GetCtx(), parames)
}

func (c *HomeController) WechatMpLogin(r *ghttp.Request) *response.JsonResponse {
	var parames *HomeReq.WechatMpLogin
	if err := r.Parse(&parames); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return HomeService.WechatMpLogin(r.GetCtx(), parames)
}

func (c *HomeController) HotSearchs(r *ghttp.Request) *response.JsonResponse {
	return HomeService.HotSearchs(r.GetCtx())
}
